package cn.zyy.dao;

import cn.zyy.entity.Clazz;
import cn.zyy.utils.JDBCUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import javax.sql.DataSource;
import java.sql.SQLException;

/**
 * 班级持久化层
 */
public class ClassDaoImpl implements ClassDao {

    @Override
    //根据班级名称查询班级编号
    public Clazz findClassByClassName(String className) {
        DataSource dataSource = JDBCUtil.getDataSource();
        QueryRunner qrn = new QueryRunner(dataSource);
        String sql = "select class_id as classId, class_name as className from class where class_name = ? ";
        Clazz clazz = null;
        try {
            clazz = qrn.query(sql, new BeanHandler<>(Clazz.class), className);
            return clazz;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return clazz;
    }

}
